<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4: 
// +----------------------------------------------------------------------+
// | SAPID: XML Sapiens Engine Demonstrator                               |
// +----------------------------------------------------------------------+
// | Author:  Max Baryshnikov aka Mephius <mb@rg.by>	                  |
// | Copyright (c) 2004 Max Baryshnikov                                   |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 08.09.04 (dd/mm/yy)
// $Id: editor.php,v 1.4 2006/02/20 08:39:46 sheiko Exp $
if (!defined("SAPID_STARTED")) die("Hacking attempt!");

include(ROOT_PATH . "/lang/".$GLOBALS["default_language"].".inc.php");

global $env;

$stylesheet = false;


if(!$wysiwyg_css_load) {
	echo '
<style>
.toolbutton { border: 1px solid white; }
</style>
';
	$wysiwyg_css_load = true;
}

	$obj_label =  $type.'.'.$name.'.value';
	if( defined("TRACEMODE") ) { 
		$block_header = ($attribs["title"]?$attribs["title"].' ('.$obj_label.")":$obj_label); 
		if($type!="qc")  
			$block_header = ($this->sapi["sdc"][$name]["title"]?$this->sapi["sdc"][$name]["title"].' ('.$obj_label.")":$obj_label);
	} else { 
		$block_header = ($attribs["title"]?$attribs["title"]:$obj_label);
		if($type!="qc")  {
			$block_header = ($this->sapi["sdc"][$name]["title"]?$this->sapi["sdc"][$name]["title"]:$obj_label);
		}
	}
	
?>



			
            <!--[if IE]>            
            <div ID="panel_<?=$name?>" style="height: 12px; margin-bottom: 3px; clear: left; background: #CEE4F2; padding: 5px 5px 5px 5px; display: none"> 
             
             
<? // Seach and replacement ?>                  
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);" title="<?=$lang["ieeditor"]["Find"]?>"
                  onClick='return StrFind(area_<?=$name?>);'
                  onMouseOut=button_out(this); type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_find.gif"
                  border="0" unselectable="on"></div>
<? // Bold ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontBold_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Bold"]?> (Ctrl+B)" onClick='return ecommand("<?=$name?>", "Bold");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_bold.gif"
                  border="0" name=up unselectable="on"></div>
<? // Underline ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontUnderline_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Underline"]?> (Ctrl+U)" onClick='return ecommand("<?=$name?>", "Underline");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_underline.gif"
                  border="0" name=up unselectable="on"></div>
<? // Italic ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontItalic_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Italic"]?> (Ctrl+I)" onClick='return ecommand("<?=$name?>", "Italic");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_italic.gif"
                  border="0" unselectable="on"></div>
<? // Enumerated list ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontInsertOrderedList_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Numbered_List"]?>"
                  onClick='return ecommand("<?=$name?>", "InsertOrderedList");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_numbers.gif"
                  border="0" unselectable="on"></div>
<? // Unordered list ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontInsertUnorderedList_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Bulletted_List"]?>"
                  onClick='return ecommand("<?=$name?>", "InsertUnorderedList");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_bullets.gif"
                  border="0" unselectable="on"></div>
<? // Increase indent ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);" title="<?=$lang["ieeditor"]["Increase_Indent"]?>"
                  onClick='return ecommand("<?=$name?>", "Outdent");' onMouseOut=button_out(this);
                  type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_decrease_indent.gif"
                  border="0" unselectable="on"></div>
<? // Decrease_Indent ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="indent_<?=$name?>" onMouseOver="button_over(this);" title="<?=$lang["ieeditor"]["Decrease_Indent"]?>"
                  onClick='return ecommand("<?=$name?>", "Indent");' onMouseOut=button_out(this);
                  type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_increase_indent.gif"
                  border="0" unselectable="on"></div>
<? // Superscript ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontSuperScript_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Superscript"]?>" onClick='return ecommand("<?=$name?>", "SuperScript");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_superscript.gif"
                  border="0" unselectable="on"></div>
<? // Subscript ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontSubScript_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Subscript"]?>" onClick='return ecommand("<?=$name?>", "SubScript");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_subscript.gif"
                  border="0" unselectable="on"></div>
                
<? // Center aligment ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontJustifyCenter_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Center"]?> (Ctrl+E)"
                  onClick='return ecommand("<?=$name?>", "JustifyCenter");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_align_center.gif"
                  border="0" unselectable="on"></div>
<? // Right aligment ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontJustifyRight_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Align_Right"]?> (Ctrl+R)"
                  onClick='return ecommand("<?=$name?>", "JustifyRight");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_align_right.gif"
                  border="0" unselectable="on"></div>
<? // Justifying ?> 
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  id="fontJustifyFull_<?=$name?>" onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Justify"]?> (Ctrl+J)"
                  onClick='return ecommand("<?=$name?>", "JustifyFull");'
                  onMouseOut="button_out2(this);" type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_align_justify.gif"
                  border="0" unselectable="on"></div>
<? // Insert image ?>
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Insert_Image"]?> (Ctrl+M)" onClick="return insimage(area_<?=$name?>.document, '<?=$name?>')"
                  onMouseOut=button_out(this); type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_image.gif"
                  border="0" unselectable="on"></div>
<? // Insert file ?>
				<div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Insert_File"]?> " onClick="return insfile(area_<?=$name?>.document, '<?=$name?>')"
                  onMouseOut=button_out(this); type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_insfile.gif"
                  border="0" unselectable="on"></div>                
<? // Insert Horizontal Rule ?>
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);" title="<?=$lang["ieeditor"]["Hr"]?>"
                  onClick='return ecommand("<?=$name?>", "InsertHorizontalRule");'
                  onMouseOut=button_out(this); type="image" height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_hr.gif"
                  border="0" unselectable="on"></div>
<? // Insert link ?>                   
                <div style="float: left; margin: 1px;"><input class="toolbutton" onMouseDown="button_down(this);"
                  onMouseOver="button_over(this);"
                  title="<?=$lang["ieeditor"]["Insert_Link"]?> (Ctrl+K)"
                  onClick="return inslink(area_<?=$name?>.document, '<?=$name?>')" onMouseOut="button_out(this);" type="image"
                  height="22" width="23"
                  src="<?=$env["http_path"]?>usr/system/images/wysiwyg/button_link.gif"
                  border="0" unselectable="on"></div>

                  
<? // Insert style ?>                   
                <div id="styletd_<?=$name?>" style="float: left; margin: 1px; display: none; margin-top: 2px;">
                 <select style="border: 1px white solid" onChange="applyStyle(area_<?=$name?>, this.value); return false;" id="styles_<?=$name?>" name="styles_<?=$name?>">
                 <option value="" style="background-color: #EEEEEE">Default style</option>
                 <option value="H1" style="background-color: #DDEEEE">Header 1</option>
                 <option value="H2" style="background-color: #DDEEEE">Header 2</option>
                 </select>
				</div>
				<br clear="both" />
			</div>
			<div style="float: right; height: 18px; overflow: hidden">
            <div style="display: block">
            <a style="cursor: pointer" onClick="return menu(panel_<?=$name?>, '<?=$name?>')"><img id="panel_<?=$name?>_but" src="<?=$env["http_path"]?>usr/system/images/but_plus.gif" width="19" height="18" alt="Open WYSIWYG tools panel" /></a>
            <a style="cursor: pointer" onClick="return htmltotext(area_<?=$name?>, '<?=$name?>')"><img src="<?=$env["http_path"]?>/usr/system/images/but2.gif" width="19" height="18" alt="HTML/Code" /></a>
            <a style="cursor: pointer" onClick="return cleanHTML(area_<?=$name?>)"><img src="<?=$env["http_path"]?>/usr/system/images/but3.gif" width="19" height="18" alt="Clean HTML" /></a>            
            </div>
            </div>
			<![endif]-->
            <div class="sapid_<?=$type?>_marker"><? print $block_header; ?></div>
			<div onMouseUp="allEvents('<?=$name?>')" contentEditable="true" id="area_<?=$name?>" style="-moz-user-modify: read-write; -moz-user-input: enabled; -moz-user-select: normal; border: 1px dotted; padding: 3px; margin-bottom: 3px;"><? if($data) print $data; else print '<br /><br /><br />'; ?></div>

<?
$GLOBALS["action_script"].="document.getElementById('" . $name . "').value = area_" . $name . ".innerHTML;\n";
$GLOBALS["form_fields"].='<textarea style="display: none;  padding-top: 0px; padding-bottom: 0px;" name="'.$name.'" id="'.$name.'">&nbsp;</textarea>
<input type="hidden" name="container['.$type.']['.$name.']" value="'.$name.'">
';
?>
            

<SCRIPT LANGUAGE="JavaScript">
	vswitcher['<?=$name?>'] = true;
	if( displayCSS("styles_<?=$name?>")==true ) styletd_<?=$name?>.style.display="block";
	//area_<?=$name?>.document.designMode = "on";
</SCRIPT>
